package com.cy.pj.common.service;

import org.springframework.stereotype.Service;

@Service
public class MailServiceImpl implements MailService {
    @Override
    public boolean sendMail(String msg) {
        //对扩展开放,对需改关闭 OCP原则
        //long t1 = System.currentTimeMillis();
        System.out.println("send->" + msg);
        //  long t2 = System.currentTimeMillis();
        //    System.out.println("send time:"+(t2-t1));
        return true;
    }
}


/*class TimeMailServiceImpl extends MailServiceImpl {
    @Override
    public boolean sendMail(String msg) {
        long t1 = System.currentTimeMillis();
        boolean flag = super.sendMail(msg);
        long t2 = System.currentTimeMillis();
        System.out.println("send time:" + (t2 - t1));
        return flag;
    }
}*/
//自己写兄弟类对目标对象进行行功能拓展
class TimeMailServiceImpl implements MailService {

    private MailService mailService;
    public TimeMailServiceImpl(MailService mailService){
        this.mailService=mailService;

    }
    @Override
    public boolean sendMail(String msg) {
        long t1 = System.nanoTime();
        boolean flag = mailService.sendMail(msg);
        long t2 = System.nanoTime();
        System.out.println("send time:"+(t2-t1));
        return false;
    }

}
